/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package g7.dao.impl;

import g7.dao.SprintDAO;
import g7.modelo.Sprint;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author julianna
 */
@Stateless
public class SprintDAOImpl implements SprintDAO{
    @PersistenceContext(name="g7Scrum")
    private EntityManager manager;
    
    @Override
    public void salvar(Sprint sprint) {
        manager.merge(sprint);
    }

    @Override
    public void excluir(Sprint sprint) {
        manager.remove(manager.getReference(Sprint.class, sprint.getId()));
    }

    @Override
    public List<Sprint> listarTudo() {
        Query query = manager.createQuery("Select s from Sprint s");
        List<Sprint> sprints = query.getResultList();
        return sprints;
    }

    @Override
    public Sprint findById(Long id) {
        Sprint sprint = manager.find(Sprint.class, id);
        return sprint;
    }

    @Override
    public Sprint procurarPorObjetivo(String objetivo) {
        Query query = manager.createQuery("Select s from Sprint s where s.objetivo like '"+objetivo+"'");
        Sprint sprint = (Sprint)query.getSingleResult();
        return sprint;
    }
    
}
